version: '{build}'
image: Visual Studio 2019
pull_requests:
  do_not_increment_build_number: true
branches:
  only:
  - master
  - main
skip_tags: true
skip_branch_with_pr: true
max_jobs: 1

configuration: Release

init:
- cmd: >-
    tzutil /s "Russian Standard Time"

    git config --global core.autocrlf input

assembly_info:
  patch: true
  file: '**\AssemblyInfo.*'
  assembly_version: '{version}'
  assembly_file_version: '{version}'
  assembly_informational_version: '{version}'

install:
- ps: >-
    $AssemblyFile = "$env:APPVEYOR_PROJECT_NAME\Properties\AssemblyInfo.cs"

    $RegularExpression = [regex] '^\[assembly: AssemblyFileVersion\(\"(\d*\.\d*\.\d*)\.\d*\"\)\]$'

    $FileContent = Get-Content $AssemblyFile

    foreach($content in $FileContent) {
      $match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
      if($match.Success) {
        $env:VERSION = $match.groups[1].value
        break;
      }
    }

    Update-AppveyorBuild -Version ("{0}.{1}" -f $env:VERSION, $env:APPVEYOR_BUILD_NUMBER)

    $CommitDateTime = [datetime]::Parse($env:APPVEYOR_REPO_COMMIT_TIMESTAMP)

    $env:BuildDate = $CommitDateTime.ToString('yyyy-MM-dd')

    $env:Site = "http://{0}.github.io/{1}" -f $env:APPVEYOR_ACCOUNT_NAME, $env:APPVEYOR_PROJECT_NAME

    Write-Host "Building v$env:APPVEYOR_BUILD_VERSION dated $env:BuildDate"

before_build:
- cmd: nuget restore

build:
  project: $(appveyor_project_name).sln
  verbosity: minimal

before_package:
- cmd: >-
    copy %APPVEYOR_PROJECT_NAME%\bin\%CONFIGURATION%\%APPVEYOR_PROJECT_NAME%.exe*

    echo %SITE%>>readme.txt

    echo [InternetShortcut]>readme.url

    echo URL=%SITE%>>readme.url

    echo %APPVEYOR_PROJECT_NAME%.exe>>Package

    echo %APPVEYOR_PROJECT_NAME%.exe.config>>Package

    echo %APPVEYOR_PROJECT_NAME% v%APPVEYOR_BUILD_VERSION% (%BUILDDATE%)>readme.txt

    echo http://%APPVEYOR_ACCOUNT_NAME%.github.io/%APPVEYOR_PROJECT_NAME%>>readme.txt

after_build:
- cmd: 7z a %APPVEYOR_PROJECT_NAME%-v%APPVEYOR_BUILD_VERSION%.zip @Package readme.txt readme.url

artifacts:
- path: $(appveyor_project_name)-v$(appveyor_build_version).zip
  name: AppZip

deploy:
- provider: GitHub
  tag: v$(appveyor_build_version)
  release: $(appveyor_project_name) v$(appveyor_build_version)
  description: '* $(appveyor_repo_commit_message)\n\nBuild #$(appveyor_build_number) by AppVeyor $(BuildDate)\nSee docs on $(Site)'
  auth_token:
    secure: LAduTcMu0l/d5XnTQicRyKZPI28h6c8w2Wn6Xg5OriF4FhWdTyGxxBwcEOBJF4Mq
  artifact: AppZip
  draft: false
  prerelease: true
  force_update: true
  on:
    branch:
      - master
      - main

only_commits:
  files:
    - '*.cs'
    - '*.yml'
